<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('代理提现账户')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            服务商编号:
                            <input type="text" name="agentNum"/>
                        </li>
                        <li>
                            姓名:
                            <input type="text" name="linkMan"/>
                        </li>
                        <li>
                            手机号:
                            <input type="text" name="linkPhone"/>
                        </li>
                        <li>
                            靓号:
                            <input type="text" name="lh"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 search-collapse">
            <span style="color:blue">[</span>
            <span style="color: blue;font-style: initial">分润账户：</span>
            <span id="fr" style="color: red;font-style: initial">0</span><span style="color: blue;font-style: initial"> 元</span>
            <span style="color:blue">]</span>
            <span style="color:blue">[</span>
            <span style="color: blue;font-style: initial">返现账户：</span>
            <span id="fx" style="color: red;font-style: initial">0</span><span style="color: blue;font-style: initial"> 元</span>
            <span style="color:blue">]</span>
            <span style="color:blue">[</span>
            <span style="color: blue;font-style: initial">流量卡账户：</span>
            <span id="llk" style="color: red;font-style: initial">0.00</span><span style="color: blue;font-style: initial"> 元</span>
            <span style="color:blue">]</span>
            <span style="color:blue">[</span>
            <span style="color: blue;font-style: initial">服务费账户：</span>
            <span id="fwf" style="color: red;font-style: initial">0.00</span><span style="color: blue;font-style: initial"> 元</span>
            <span style="color:blue">]</span>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success single disabled" onclick="accountUpdate()">
                <i class="fa fa-edit"></i> 账户状态变更
            </a>
            <a class="btn btn-success single disabled" onclick="accountAdjust()">
                <i class="fa fa-edit"></i> 账户调增/调减
            </a>
            <!-- <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="walletDetails:walletDetails:export">
                 <i class="fa fa-download"></i> 导出
             </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" class="table text-nowrap"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var orderState = [[${@dict.getType('orderState')}]];
    var merType = [[${@dict.getType('merType')}]];
    var editFlag = [[${@permission.hasPermi('walletDetails:walletDetails:edit')}]];
    var removeFlag = [[${@permission.hasPermi('walletDetails:walletDetails:remove')}]];
    var datas = [[${@dict.getType('agent_status')}]];

    var prefix = ctx + "walletDetails/walletDetails";

    $(function() {
        var options = {
            url: prefix + "/agentAccountList",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "代理提现账户",
            responseHandler:responseHandler,
            clickToSelect:true,
            columns: [
                {
                    radio: true
                },
                {
                    field: 'AGENT_NUM',
                    title: '服务商编号'
                },
                {
                    field: 'AGENT_NAME',
                    title: '服务商名称'
                },
                {
                    field: 'AGENT_STATUS',
                    title: '服务商状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'STATUS',
                    title: '账户状态',
                    formatter: function (value, row, index) {
                       if (value == '3') {
                            return '<span style="color: green">启用</span>';
                        } else if (value == '4') {
                            return '<span style="color: red">关停</span>';
                        } else {
                            return '<span style="color: red">未知</span>';
                        }
                    },
                },
                {
                    field: 'AMOUNT',
                    title: '分润账户',
                    formatter: function (value, row, index) {
                        var dataValue = value;
                        return "<span>" + dataValue + "</span>" + " " + statusTools1(row);
                    },
                },
                {
                    field: 'R_AMOUNT',
                    title: '返现账户',
                    formatter: function (value, row, index) {
                        return value + " " + statusTools2(row);
                    },
                },
                {
                    field: 'AMOUNT_TWO',
                    title: '流量卡账户',
                    formatter: function (value, row, index) {
                        return value + " " + statusTools3(row);
                    },
                },
                {
                    field: 'R_AMOUNT_TWO',
                    title: '服务费账户',
                    formatter: function (value, row, index) {
                        return value + " " + statusTools4(row);
                    },
                },
            ]
        };
        $.table.init(options);
    });

    function statusTools1(row) {
        if (row.ACC_STATUS1 == '0') {
            return '<i style="position:relative;top:4px;left: 5px;"  class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.AGENT_NUM + '\',\'1\')"></i> ';
        } else {
            return '<i  style="position:relative;top:4px;left: 5px;" class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.AGENT_NUM + '\',\'1\')"></i> ';
        }
    }

    function statusTools2(row) {
        if (row.ACC_STATUS2 == 0) {
            return '<i  style="position:relative;top:4px;left: 5px;" class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.AGENT_NUM + '\',\'2\')"></i> ';
        } else {
            return '<i  style="position:relative;top:4px;left: 5px;" class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.AGENT_NUM + '\',\'2\')"></i> ';
        }
    }

    function statusTools3(row) {
        if (row.ACC_STATUS3 == 0) {
            return '<i  style="position:relative;top:4px;left: 5px;" class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.AGENT_NUM + '\',\'3\')"></i> ';
        } else {
            return '<i  style="position:relative;top:4px;left: 5px;" class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.AGENT_NUM + '\',\'3\')"></i> ';
        }

    }

    function statusTools4(row) {
        if (row.ACC_STATUS4 == 0) {
            return '<i   style="position:relative;top:4px;left: 5px;" class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.AGENT_NUM + '\',\'4\')"></i> ';
        } else {
            return '<i   style="position:relative;top:4px;left: 5px;" class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.AGENT_NUM + '\',\'4\')"></i> ';
        }
    }

    function accountUpdate() {
        var agentNum = $.table.selectColumns("AGENT_NUM");
        $.modal.open("账户状态变更", prefix + "/accountUpdate?agentNum=" + agentNum, '788', '350');
    }


    function accountAdjust() {
        var agentNum = $.table.selectColumns("AGENT_NUM");
        $.modal.open("账户调整", prefix + "/accountAdjust?agentNum=" + agentNum, '788', '550');
    }


    /* 冻结 */
    function disable(agentNum,statusType) {
        $.modal.confirm("确认要冻结吗？", function() {
            $.operate.post(prefix + "/updateAgentAccount", { "agent_num": agentNum, "status": -1, "statusType": statusType });
        })
    }

    /* 解冻 */
    function enable(agentNum,statusType) {
        $.modal.confirm("确认要解冻吗？", function() {
            $.operate.post(prefix + "/updateAgentAccount", { "agent_num": agentNum, "status": 0, "statusType": statusType  });
        })
    }


    function responseHandler(res) {
        // 防止 res 或 res.data 为空
        var data = res && res.data ? res.data : {};

        // 更新账户余额
        $("#fr").text(data.AMOUNT || 0);
        $("#fx").text(data.R_AMOUNT || 0);
        $("#llk").text(data.AMOUNT_TWO || 0);
        $("#fwf").text(data.R_AMOUNT_TWO || 0);

        // 返回表格数据
        return {
            rows: data.rows || [], // 表格数据
            total: data.total || 0 // 总条数
        };
    }



</script>
</body>
</html>
